﻿#region Imports
using System;
using System.Drawing;
using System.Windows.Forms;
using CommonUtilities.Extensions;
using CommonUtilities.Util;
#endregion

namespace CommonUtilities.Controls
{
    /// <summary>
    /// CommonUtilities Button
    /// (inherited from System.Windows.Forms.Button)
    /// </summary>
    public class CUtil_Button : Button
    {
        #region Declarations
        public event EventHandler MouseEnter;
        public event EventHandler MouseLeave;
        #endregion

        #region Properties
        private FontStyle initFontStyle;
        public FontStyle InitialFontStyle { get { return initFontStyle; } }
        #endregion

        #region Constructors
        public CUtil_Button()
            : base()
        {
            base.MouseEnter += new EventHandler(CUtil_Button_MouseEnter);
            base.MouseLeave += new EventHandler(CUtil_Button_MouseLeave);
        }
        #endregion

        #region Formatting events
        private void CUtil_Button_MouseEnter(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            // Back-up of initialized values
            this.initFontStyle = btn.Font.Style;

            btn.Font = new Font(btn.Font.FontFamily, btn.Font.Size, FontStyle.Bold, btn.Font.Unit, btn.Font.GdiCharSet);

            if (!this.MouseEnter.IsNull())
                this.MouseEnter(sender, e);
        }

        private void CUtil_Button_MouseLeave(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            btn.Font = new Font(btn.Font.FontFamily, btn.Font.Size, InitialFontStyle, btn.Font.Unit, btn.Font.GdiCharSet);

            if (!this.MouseLeave.IsNull())
                this.MouseLeave(sender, e);
        }
        #endregion

        #region Methods
        public override string ToString()
        {
            return Utilities.ToString(this);
        }
        #endregion
    }
}
